package cn.uniquesoft.api;

import cn.uniquesoft.service.ICompanyService;
import cn.uniquesoft.vo.CompanyVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping(value = "/api/company")
public class ApiCompanyController {
    @Value("${resource.pagesize}")
    private int pagesize;
    @Autowired
    private ICompanyService companyService;


    @RequestMapping(value = "/getCompanyList")
    @ResponseBody
    public List<CompanyVO> getCompanyList() {
        return this.companyService.findItemsGroupByItype();
    }


    @RequestMapping(value = "/getOneCompany")
    @ResponseBody
    public CompanyVO getOneCompany( int iid) {
        return this.companyService.findOneById(iid);
    }

    @RequestMapping(value = "/getCompanyListByItype")
    @ResponseBody
    public List<CompanyVO> getCompanyListByItype(int iid,int itype) {
        List<CompanyVO> itemList = new ArrayList<>();
        CompanyVO item =new CompanyVO();
              item.setIid(iid);
              item.setItype(itype);
              item.setPageSize(this.pagesize);
                itemList = this.companyService.getCompanyListByItype(item);

        return itemList;
    }
}
